import random
coin = 5000

num = random.randint(1, 100)

while True:

    guess = int(input("猜数字:"))

    if 1 <= guess <= 100:

        if coin > 0:
            if guess == num:

                coin += 3000
                print("恭喜猜中,幸运数字为：", num, "剩余金币为：", coin)
                select = input('是否开始新的一轮:y or n\n')
                if select == 'y':
                    num = random.randint(1, 100)
                elif select == 'n':
                    break
            elif guess > num:

                coin -= 500
                print("大了", "剩余金币为：", coin)
            else:

                coin -= 500
                print("小了", "剩余金币为：", coin)

        else:
            print("金币不足，请及时充值")
            break
    else:
        print("请输入1~100的数字")
